package com.mixmer.excelanalysis.excel;

public class CellLocation {

    private int sheetIndex;

    private int rowIndex;

    private int colIndex;

    public CellLocation(int sheetIndex, int rowIndex, int colIndex) {
        this.sheetIndex = sheetIndex;
        this.rowIndex = rowIndex;
        this.colIndex = colIndex;
    }

    public int getSheetIndex() {
        return sheetIndex;
    }

    public void setSheetIndex(int sheetIndex) {
        this.sheetIndex = sheetIndex;
    }

    public int getRowIndex() {
        return rowIndex;
    }

    public void setRowIndex(int rowIndex) {
        this.rowIndex = rowIndex;
    }

    public int getColIndex() {
        return colIndex;
    }

    public void setColIndex(int colIndex) {
        this.colIndex = colIndex;
    }

    public static CellLocation getCellLocation(String target) {
        // 1-2-B
        // 解析表达式，拿到具体单元格坐标
        String[] cellLocationExpression = target.split("-");
        int sheetIndex = Integer.parseInt(cellLocationExpression[0]) - 1;
        int rowIndex = Integer.parseInt(cellLocationExpression[1]) - 1;
        int colIndex = cellLocationExpression[2].toCharArray()[0] - 65;
        return new CellLocation(sheetIndex, rowIndex, colIndex);
    }

}
